import { InputData } from './types'
import {utils, writeFile} from 'xlsx'

export default function ({ data, inputs, outputs, logger, onError }: RuntimeParams<any>) {
  inputs['input'](async (val: InputData) => {
    const wb = utils.book_new()
    for (const dataItem of val.sheetList) {
      const sheet = utils.json_to_sheet(dataItem.sheetData)
      utils.book_append_sheet(wb, sheet, dataItem.sheetName)
    }
    writeFile(wb, val.fileName)
    outputs['exportComplete']()
  })
}
